package com.dd.cloud.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dd.cloud.user.entity.chknowl.*;
import com.dd.cloud.user.req.chknowl.*;
import com.dd.cloud.user.res.chknowl.*;
import com.dd.cloud.user.service.chknowl.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 中医知识库 前端控制器
 * </p>
 *
 * @author czg
 * @since 2022-07-04
 */
@RestController
@RequestMapping("/chknowl")
@Validated
public class ChknowlCurrController {
    @Autowired
    private IChknowlBooksCtlgService chknowlBooksCtlgService;
    @Autowired
    private IChknowlBooksPresentService chknowlBooksPresentService;
    @Autowired
    private IChknowlCurrService chknowlCurrService;
    @Autowired
    private IChknowlChDrgusService chknowlChDrgusService;
    @Autowired
    private IChknowlChPatentService chknowlChPatentService;
    @Autowired
    private IChknowlFoodModelService chknowlFoodModelService;
    @Autowired
    private IChknowlConsiliaService chknowlConsiliaService;
    @Autowired
    private IDiseaseDiagnosisCodeService diseaseDiagnosisCodeService;
    @Autowired
    private IChkonwlChDrugsTropismService chkonwlChDrugsTropismService;
    @Autowired
    private IChkonwlDoctorBookService chkonwlDoctorBookService;
    @Autowired
    private IChkonwlDoctorBookSettingService doctorBookSettingService;
    @Autowired
    private IChkonwlDoctorBookReadRecordService doctorBookReadRecordService;
    @Autowired
    private IChknowlBooksCategoryService booksCategoryService;
    @Autowired
    private IChknowlChVideoService chknowlChVideoService;
    @Autowired
    private IChkonwDoctorReadSettingService chkonwDoctorReadSettingService;
    @Autowired
    private IChnowlVideoRecordService chnowlVideoRecordService;
    @Autowired
    private IChknowlChDrugsCategoryService chDrugsCategoryService;
    @Autowired
    private IChknowlCurrCategoryService chknowlCurrCategoryService;
    @Autowired
    private IChknowlReadCountService chknowlReadCountService;

    /**
     * word文档保存古籍文章
     *
     * @return word文档保存古籍文章
     */
    @PostMapping("/save/word")
    public ResponseEntity<String> saveByWrod(MultipartFile[] files, @NotBlank(message = "大类不能为空") String category) {
        String msg = chknowlBooksCtlgService.saveBooksFromWord(files, category);
        return ResponseEntity.ok(msg);
    }


    /**
     * 查询书籍的目录
     *
     * @return 分页查询经验方
     */
    @GetMapping("/books/chapter/list")
    public ResponseEntity<List<ChknowlBooksCtlg>> getCatalogueList(@NotNull(message = "书籍id不能为空") Integer bookId) {
        List<ChknowlBooksCtlg> list = chknowlBooksCtlgService.getChknowlBooksCtlgList(bookId);
        return ResponseEntity.ok(list);
    }

    /**
     * 查询所有的书籍大类
     *
     * @return 分页查询经验方
     */
    @GetMapping("/books/ctlg")
    public ResponseEntity<List<ChBooksCategoryRes>> getContentList() {
        List<ChBooksCategoryRes> res = chknowlBooksPresentService.getCategory();
        return ResponseEntity.ok(res);
    }

    /**
     * 查询所有的书籍
     *
     * @return
     */
    @GetMapping("/books/ctlg/page")
    public ResponseEntity<IPage<ChknowlBooksPresentPageRes>> getContentList(@Valid ChBooksPageReq req) {
        IPage<ChknowlBooksPresentPageRes> page = chknowlBooksPresentService.getCategoryBookList(req);
        return ResponseEntity.ok(page);
    }


    /**
     * 查询大类下所有的书籍
     *
     * @return 分页查询经验方
     */
    @GetMapping("/books/ctlg/id")
    public ResponseEntity<ChknowlBooksPresentPageRes> getContentList(@NotNull(message = "书籍id不能为空") Integer id) {
        ChknowlBooksPresentPageRes res = chknowlBooksPresentService.getCategoryBook(id);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询书籍的内容(阅读时)
     *
     * @param bookId 书籍id
     * @param rankId 目录层级
     * @return
     */
    @GetMapping("/books/content")
    public ResponseEntity<ChknowlBooksCtlg> getBookContent(@NotNull(message = "书籍id不能为空") Integer bookId, Integer rankId) {
        ChknowlBooksCtlg chknowlBooksCtlg = chknowlBooksPresentService.getContent(bookId, rankId);
        return ResponseEntity.ok(chknowlBooksCtlg);
    }

    /**
     * 查询书籍的详情
     *
     * @param bookId 书籍id
     * @return
     */
    @GetMapping("/books/content/detail")
    public ResponseEntity<ChknowlBooksDetailRes> getBookContentDetail(@RequestParam("bookId") Integer bookId) {
        ChknowlBooksDetailRes chknowlBooksCtlg = chknowlBooksPresentService.getBookDetail(bookId);
        return ResponseEntity.ok(chknowlBooksCtlg);
    }

    /**
     * 添加或修改书籍的内容
     *
     * @param req
     * @return
     */
    @PostMapping("/books/add")
    public ResponseEntity<Void> addBookContent(@Valid ChknowlBooksCreateReq req) {
        chknowlBooksPresentService.addBook(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 添加或修改书籍的内容
     *
     * @param req
     * @return
     */
    @PostMapping("/books/update")
    public ResponseEntity<Void> updateBookContent(@Valid ChknowlBooksUpdateReq req) {
        chknowlBooksPresentService.updateBook(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 添加或修改书籍的内容
     *
     * @param id
     * @return
     */
    @PostMapping("/books/update/status")
    public ResponseEntity<Void> updateBookContentStatus(@NotNull(message = "id不能为空") Integer id, @NotNull(message = "状态不能为空") Integer status) {
        chknowlBooksPresentService.updateBookContentStatus(id, status);
        return ResponseEntity.ok().build();
    }


    /**
     * 导入中药材详细信息数据
     *
     * @return 导入经验方数据
     */
    @PostMapping("/chDrugs/import/excel")
    public ResponseEntity<Void> importExcelChinese(@NotNull(message = "文件不能为空") MultipartFile file) {
        chknowlChDrgusService.importMiddleDrugs(file);
        return ResponseEntity.ok().build();
    }

    /**
     * 分页查询中药材
     *
     * @return 分页查询中药材
     */
    @GetMapping("/chDrugs/page")
    public ResponseEntity<IPage<ChknowlChDrugsPageRes>> getChinesePage(@Valid ChDrugsQueryReq req) {
        IPage<ChknowlChDrugsPageRes> res = chknowlChDrgusService.queryChDrugsPage(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 关键字查询中药材
     *
     * @return 中药材
     */
    @GetMapping("/chDrugs/list/keyword")
    public ResponseEntity<List<ChUserSearchListRes>> getChineseListKeyword(String keyword) {
        List<ChUserSearchListRes> res = chknowlChDrgusService.getChDrugsListByKeyword(keyword);
        return ResponseEntity.ok(res);
    }

    /**
     * id查询中药材详细信息
     *
     * @return
     */
    @GetMapping("/chDrugs/detail/id")
    public ResponseEntity<ChknowlChDrugsDetailRes> getChineseDetailId(@NotNull(message = "id不能为空") Integer id) {
        ChknowlChDrugsDetailRes res = chknowlChDrgusService.queryChDrugsDetail(id);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询中药分类详情
     */
    @GetMapping("/chDrugs/category/detail")
    public ResponseEntity<ChknowlChDrugsCategory> queryChknowChDrugCategoryDetail(@RequestParam("categoryId") Integer categoryId) {
        ChknowlChDrugsCategory category = chDrugsCategoryService.queryChknowChDrugCategoryDetail(categoryId);
        return ResponseEntity.ok(category);
    }


    /**
     * 添加中药材
     *
     * @return
     */
    @PostMapping("/chDrugs/add")
    public ResponseEntity<Void> createChDrugs(@Valid ChDrugsCreateReq req) {
        chknowlChDrgusService.createChDrugs(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改中药材
     *
     * @return
     */
    @PostMapping("/chDrugs/update")
    public ResponseEntity<Void> updateChDrugs(@Valid ChDrugsUpdateReq req) {
        chknowlChDrgusService.updateChDrugs(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改中药材状态
     *
     * @return
     */
    @PostMapping("/chDrugs/update/status")
    public ResponseEntity<Void> updateChDrugsStatus(@NotNull(message = "id不能为空") Integer id, @NotNull(message = "状态不能为空") Integer status) {
        chknowlChDrgusService.updateChDrugsStatus(id, status);
        return ResponseEntity.ok().build();
    }

    /**
     * 导入中成药详细信息数据
     *
     * @return 导入经验方数据
     */
    @PostMapping("/chPatent/import/excel")
    public ResponseEntity<Void> importExcelPatent(@NotNull(message = "文件不能为空") MultipartFile file) {
        chknowlChPatentService.importChPatent(file);
        return ResponseEntity.ok().build();
    }

    /**
     * 分页查询中成药
     *
     * @return 分页查询中成药
     */
    @GetMapping("/chPatent/page")
    public ResponseEntity<IPage<ChknowlChPatent>> getPatentPage(@Valid ChPatentQueryReq req) {
        IPage<ChknowlChPatent> res = chknowlChPatentService.queryMiddlePatentPage(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 关键字查询中成药
     *
     * @return 关键字查询中成药
     */
    @GetMapping("/chPatent/list/keyword")
    public ResponseEntity<List<ChUserSearchListRes>> getPatentListKeyword(String keyword) {
        List<ChUserSearchListRes> res = chknowlChPatentService.getChPatentListByKeyword(keyword);
        return ResponseEntity.ok(res);
    }

    /**
     * id查询中成药详细信息
     *
     * @return id查询中成药详细信息
     */
    @GetMapping("/chPatent/detail/id")
    public ResponseEntity<ChknowlChPatent> getPatentDetailId(@NotNull(message = "id不能为空") Integer id) {
        ChknowlChPatent res = chknowlChPatentService.queryChPatentDetail(id);
        return ResponseEntity.ok(res);
    }

    /**
     * id查询中成药详细信息
     *
     * @return id查询中成药详细信息
     */
    @PostMapping("/chPatent/add")
    public ResponseEntity<Void> addPatent(@Valid ChPatentCreateReq req) {
        chknowlChPatentService.createChPatent(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改中成药详细信息
     *
     * @return
     */
    @PostMapping("/chPatent/update")
    public ResponseEntity<Void> upatePatent(@Valid ChPatentUpdateReq req) {
        chknowlChPatentService.updateChPatent(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改中成药状态
     *
     * @return id数据id
     */
    @PostMapping("/chPatent/update/status")
    public ResponseEntity<Void> upatePatentStatus(@NotNull(message = "id不能为空") Integer id, @NotNull(message = "状态不能为空") Integer status) {
        chknowlChPatentService.updateChPatentStatus(id, status);
        return ResponseEntity.ok().build();
    }


    /**
     * 查询药食同源药材列表,多条件分页查询
     *
     * @param req 多条件
     * @return
     */
    @GetMapping("/food/page")
    public ResponseEntity<IPage<ChknowlFoodModelPageRes>> queryDrugsFoodModelTerms(@Valid FoodModelQueryReq req) {
        IPage<ChknowlFoodModelPageRes> iPage = chknowlFoodModelService.queryFoodModelTerms(req);
        return ResponseEntity.ok(iPage);
    }

    /**
     * 查询药食同源药材详情
     *
     * @param id 编号
     * @return
     */
    @GetMapping("/food/detail/id")
    public ResponseEntity<ChknowlFoodModelPageRes> queryDrugsFoodModel(Integer id) {
        ChknowlFoodModelPageRes dfm = chknowlFoodModelService.queryFoodModel(id);
        return ResponseEntity.ok(dfm);
    }

    /**
     * 添加药食同源药材信息
     *
     * @param req 药食同源药材信息
     * @return
     */
    @PostMapping("/food/add")
    public ResponseEntity<Void> addDrugsFoodModel(@Valid FoodModelCreateReq req) {
        chknowlFoodModelService.addFoodModel(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 批量导入药食同源数据
     *
     * @param file excel文件
     * @return
     */
    @PostMapping("/food/import/excel")
    public ResponseEntity<Void> addBatchDrugsFoodModel(@NotNull(message = "文件不能为空") MultipartFile file) {
        chknowlFoodModelService.addBatchFoodModel(file);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改药食同源药材信息
     *
     * @param req 药食同源药材信息
     * @return
     */
    @PostMapping("/food/update")
    public ResponseEntity<Void> updateFoodModel(@Valid FoodModelUpdateReq req) {
        chknowlFoodModelService.updateFoodModel(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改药食同源药材信息状态
     *
     * @param id 数据id
     * @return
     */
    @PostMapping("/food/update/status")
    public ResponseEntity<Void> updateFoodModelStatus(@NotNull(message = "id不能为空") Integer id,
                                                      @NotNull(message = "状态不能为空") Integer status) {
        chknowlFoodModelService.updateFoodModelStatus(id, status);
        return ResponseEntity.ok().build();
    }


    /**
     * 查询常用方
     */
    @GetMapping("/curr/often/List")
    public ResponseEntity<List<ChknowlCurrRes>> queryOftenCurrList() {
        List<ChknowlCurrRes> res = chknowlCurrService.queryOftenCurrList();
        return ResponseEntity.ok(res);
    }


    /**
     * 查询方剂分类
     */
    @GetMapping("/curr/category/list")
    public ResponseEntity<List<ChknowlCurrRes>> queryCategoryList() {
        List<ChknowlCurrRes> categories = chknowlCurrCategoryService.queryCategoryList();
        return ResponseEntity.ok(categories);
    }


    /**
     * 分页查询方剂
     *
     * @return 分页查询方剂
     */
    @GetMapping("/curr/page")
    public ResponseEntity<Page<ChknowlCurrPageRes>> queryDepartMents(@Valid CurrListPageReq req) {
        Page<ChknowlCurrPageRes> deps = chknowlCurrService.getExperByPage(req);
        return ResponseEntity.ok(deps);
    }


    /**
     * id获取方剂
     *
     * @return id获取方剂
     */
    @GetMapping("/curr/detail/id")
    public ResponseEntity<ChknowlCurr> getPresCurrById(@NotNull(message = "经验方id不能为空") Integer id) {
        ChknowlCurr presCurr = chknowlCurrService.getPresCurrById(id);
        return ResponseEntity.ok(presCurr);
    }

    /**
     * 添加方剂
     *
     * @param experPres
     */
    @PostMapping("/curr/add")
    public ResponseEntity<Void> createExper(@Valid ChknowlCurrCreateReq experPres) {
        chknowlCurrService.createExper(experPres);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改方剂
     *
     * @return 修改方剂
     */
    @PostMapping("/curr/update")
    public ResponseEntity<Void> updateId(@Valid ChknowlCurrUpdateReq experPres) {
        chknowlCurrService.updateExper(experPres);
        return ResponseEntity.ok().build();
    }

    /**
     * 批量修改经验方状态
     * t
     *
     * @return 批量修改经验方状态
     */
    @PostMapping("/curr/update/status/batch")
    public ResponseEntity<Void> updateBatch(@NotEmpty(message = "操作的id不能空") String ids, @NotNull(message = "状态不能空") Integer status) {
        chknowlCurrService.updateBatchStatus(ids, status);
        return ResponseEntity.ok().build();
    }

    /**
     * 导入经验方数据
     *
     * @return 导入经验方数据
     */
    @PostMapping("/curr/import/excel")
    public ResponseEntity<Void> importExcel(@NotNull(message = "请选择文件") MultipartFile file) {
        chknowlCurrService.importPresCurrFromExcel(file);
        return ResponseEntity.ok().build();
    }

    /**
     * 导出经验方数据到excel
     *
     * @return 导出经验方数据到excel
     */
    @GetMapping("/curr/export/excel")
    public ResponseEntity<Void> exportExcel(HttpServletResponse response) {
        chknowlCurrService.exportPresCurrtoExcel(response);
        return ResponseEntity.ok().build();
    }


    /**
     * word文档保存医案
     *
     * @return word文档保存医案
     */
    @PostMapping("/consilia/import/word")
    public ResponseEntity<Void> saveConsiliaByWrod(@NotNull(message = "请选择文件") MultipartFile file) {
        chknowlConsiliaService.importConsiliaWord(file);
        return ResponseEntity.ok().build();
    }

    /**
     * 分页查询医案
     */
    @GetMapping("/consilia/page")
    public ResponseEntity<IPage<ChknowlConsiliaPageRes>> getConsiliaPage(@Valid ConsiliaPageReq req) {
        IPage<ChknowlConsiliaPageRes> page = chknowlConsiliaService.getConsiliaPage(req);
        return ResponseEntity.ok(page);
    }

    /**
     * id查询医案
     *
     * @return 查询医案
     */
    @GetMapping("/consilia/detail/id")
    public ResponseEntity<ChknowlConsilia> getConsiliaById(@NotNull(message = "id不能为空") Integer id) {
        ChknowlConsilia presConsilia = chknowlConsiliaService.getConsiliaById(id);
        return ResponseEntity.ok(presConsilia);
    }

    /**
     * 添加医案
     *
     * @return 医案
     */
    @PostMapping("/consilia/add")
    public ResponseEntity<Void> addConsilia(@Valid ChknowlConsiliaCreateReq req) {
        chknowlConsiliaService.addConsilia(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改医案
     *
     * @return 医案
     */
    @PostMapping("/consilia/update")
    public ResponseEntity<Void> updateConsilia(@Valid ChknowlConsiliaUpdateReq req) {
        chknowlConsiliaService.updateConsilia(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改医案状态
     *
     * @return 医案
     */
    @PostMapping("/consilia/update/status")
    public ResponseEntity<Void> updateConsiliaStatus(@NotNull(message = "id不能为空") Integer id, @NotNull(message = "状态不能为空") Integer status) {
        chknowlConsiliaService.updateChConsiliaStatus(id, status);
        return ResponseEntity.ok().build();
    }

    /**
     * 导入excel疾病诊断编码数据
     *
     * @param file
     */
    @PostMapping("/disease/diagnosis/code/import")
    public ResponseEntity<Void> importDiseaseDiagnosisCodeExcel(MultipartFile file) {
        diseaseDiagnosisCodeService.importDiseaseDiagnosisCodeExcel(file);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询中医诊断编码名称数据
     *
     * @param req
     * @return
     */
    @GetMapping("/disease/diagnosis/code/page")
    public ResponseEntity<IPage<DiseaseDiagnosisCodePageRes>> queryDiseaseDiagnosisCodePage(@Valid DiseaseDiagnosisCodePageReq req) {
        IPage<DiseaseDiagnosisCodePageRes> res = diseaseDiagnosisCodeService.queryDiseaseDiagnosisCodePage(req);
        return ResponseEntity.ok(res);
    }


    /**
     * 查询性味归经赛选列表
     */
    @GetMapping("/tropism/list")
    public ResponseEntity<List<ChkonwlChDrugsTropism>> queryTropismList() {
        List<ChkonwlChDrugsTropism> res = chkonwlChDrugsTropismService.queryTropismList();
        return ResponseEntity.ok(res);
    }

    /**
     * 根据条件赛选
     */
    @GetMapping("/drugs/tropism/list")
    public ResponseEntity<List<ChkonwlDrugsRes>> queryDrugsList(ChkonwlDrugsReq chkonwlDrugsReq) {
        List<ChkonwlDrugsRes> res = chknowlChDrgusService.queryDrugsList(chkonwlDrugsReq);
        return ResponseEntity.ok(res);
    }


    /**
     * 我的书架
     */
    @GetMapping("/doctor/book/list")
    public ResponseEntity<IPage<ChknowlBooksPresent>> queryDoctorBook(@Valid ChBooksPageReq req) {
        IPage<ChknowlBooksPresent> res = chkonwlDoctorBookService.queryDoctorBook(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 添加书籍
     */
    @PostMapping("/doctor/book")
    public ResponseEntity<Void> addDoctorBook(@NotNull(message = "书籍id不能为空") Integer bookId,
                                              @NotNull(message = "医生id不能空") Integer doctorId) {
        chkonwlDoctorBookService.addDoctorBook(bookId, doctorId);
        return ResponseEntity.ok().build();
    }

    /**
     * 移除书籍
     */
    @PostMapping("/remove/book")
    public ResponseEntity<Void> removeDoctorBook(@NotBlank(message = "书籍id不能为空") String bookIds,
                                                 @NotNull(message = "医生id不能为空") Integer doctorId) {
        chkonwlDoctorBookService.chkonwlDoctorBookService(bookIds, doctorId);
        return ResponseEntity.ok().build();
    }

    /**
     * 书籍是否存在
     */
    @GetMapping("/doctor/book/isHave")
    public ResponseEntity<Boolean> queryIsHaveBook(@RequestParam("bookId") Integer bookId,
                                                   @RequestParam("doctorId") Integer doctorId) {
        Boolean res = chkonwlDoctorBookService.queryIsHaveBook(bookId, doctorId);
        return ResponseEntity.ok(res);
    }

    /**
     * 添加设置(书签,上一次查看记录)
     */
    @PostMapping("/doctor/book/setting")
    public ResponseEntity<Void> addDoctorBookSetting(@Valid @RequestBody ChknowlBookDoctorSettingReq req) {
        doctorBookSettingService.addDoctorBookSetting(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询书签
     */
    @GetMapping("/doctor/book/setting/page")
    public ResponseEntity<IPage<ChkonwlDoctorBookSetting>> queryDoctorBookSettingPage(@Valid ChkonwlBookSettingReq req) {
        IPage<ChkonwlDoctorBookSetting> res = doctorBookSettingService.queryDoctorBookSettingPage(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 移除书签
     */
    @PostMapping("/remove/book/setting")
    public ResponseEntity<Void> removeBookSetting(@NotNull(message = "书签id不能为空") Integer id) {
        doctorBookSettingService.removeBookSetting(id);
        return ResponseEntity.ok().build();
    }

    /**
     * 此页是否为书签
     */
    @GetMapping("/book/is/setting")
    public ResponseEntity<Boolean> selectBookIsSetting(@RequestParam("bookId") Integer bookId,
                                                       @RequestParam("doctorId") Integer doctorId,
                                                       @RequestParam("cfi") String cfi) {
        boolean flag = doctorBookSettingService.selectBookIsSetting(bookId, doctorId, cfi);
        return ResponseEntity.ok(flag);
    }

    /**
     * 添加第一次查看此书记录
     */
    @PostMapping("/doctor/book/read/first/record")
    public ResponseEntity<Void> addDoctorBookReadFirstRecord(@NotNull(message = "医生id不能为空") Integer doctorId) {
        doctorBookReadRecordService.addDoctorBookReadFirstRecord(doctorId);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询是否第一次查看此书
     */
    @GetMapping("/doctor/book/isHave/read/first/record")
    public ResponseEntity<Boolean> queryDoctorBookReadFirstRecord(@RequestParam("doctorId") Integer doctorId) {
        return ResponseEntity.ok(doctorBookReadRecordService.queryDoctorBookReadFirstRecord(doctorId));
    }

    /**
     * 添加用户阅读器设置
     */
    @PostMapping("/doctor/read/setting")
    public ResponseEntity<Void> addDoctorReadSetting(@Valid @RequestBody ChnowlReadSettingReq chnowlReadSettingReq) {
        chkonwDoctorReadSettingService.addDoctorReadSetting(chnowlReadSettingReq);
        return ResponseEntity.ok().build();
    }


    /**
     * 查询用户阅读设置
     */
    @GetMapping("/doctor/read/setting/detail")
    public ResponseEntity<ChkonwDoctorReadSetting> queryDoctorReadSetting(@RequestParam("doctorId") Integer doctorId) {
        ChkonwDoctorReadSetting chkonwDoctorReadSetting = chkonwDoctorReadSettingService.queryDoctorReadSetting(doctorId);
        return ResponseEntity.ok(chkonwDoctorReadSetting);
    }


    /**
     * 我的课程
     */
    @GetMapping("/video/page")
    public ResponseEntity<IPage<ChknowlChVideo>> queryVideoPage(@Valid ChkonwlVideoReq chkonwlVideoReq) {
        IPage<ChknowlChVideo> res = chknowlChVideoService.chknowlChVideoService(chkonwlVideoReq);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询课程详情
     */
    @GetMapping("/video/detail")
    public ResponseEntity<ChknowlChVideo> queryVideoById(@RequestParam("id") Integer id) {
        ChknowlChVideo chknowlChVideo = chknowlChVideoService.queryVideoById(id);
        return ResponseEntity.ok(chknowlChVideo);
    }

    /**
     * 书籍分类
     */
    @GetMapping("/book/category/list")
    public ResponseEntity<List<ChknowlBooksCategory>> queryBookCategoryList() {
        List<ChknowlBooksCategory> res = booksCategoryService.queryBookCategoryList();
        return ResponseEntity.ok(res);
    }

    /**
     * 查看上次记录
     */
    @GetMapping("/doctor/book/read/record")
    public ResponseEntity<ChkonwlDoctorBookSetting> queryReadBookReadRecord(@RequestParam("bookId") Integer bookId) {
        ChkonwlDoctorBookSetting res = doctorBookSettingService.queryReadBookReadRecord(bookId);
        return ResponseEntity.ok(res);
    }

    /**
     * 添加课程观看次数
     */
    @PostMapping("/video/update/num")
    public ResponseEntity<Void> updateVideoNum(@RequestParam("videoId") Integer videoId) {
        chknowlChVideoService.updateVideoNum(videoId);
        return ResponseEntity.ok().build();
    }


    /**
     * 添加观看视频记录
     */
    @PostMapping("/video/record")
    public ResponseEntity<Void> addVideoRecord(@Valid @RequestBody ChnowlVideoReq chkonwlVideoReq) {
        chnowlVideoRecordService.addVideoRecord(chkonwlVideoReq);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询观看记录
     */
    @GetMapping("/video/chapter/record/detail")
    public ResponseEntity<ChnowlVideoRecord> queryVideoRecord(@RequestParam("chapterId") Integer chapterId) {
        ChnowlVideoRecord chnowlVideoRecord = chnowlVideoRecordService.queryVideoRecord(chapterId);
        return ResponseEntity.ok(chnowlVideoRecord);
    }


    /**
     * 手动导入书籍路径
     */
    @PostMapping("/book/url")
    public ResponseEntity<Void> addBookBatch(@NotNull(message = "请上传文件") MultipartFile[] files) {
        chknowlBooksPresentService.addBookBatch(files);
        return ResponseEntity.ok().build();
    }

//    /**
//     * 手动导入书籍
//     */
//    @PostMapping("/book/import/two")
//    public ResponseEntity<Void> importBookUrlBatchTwo(@NotNull(message = "请上传文件") MultipartFile file) {
//        chknowlBooksPresentService.importBookBatchTwo(file);
//        return ResponseEntity.ok().build();
//    }

    /**
     * 手动导入书籍
     */
    @PostMapping("/book/import")
    public ResponseEntity<Void> importBookUrlBatch(@NotNull(message = "请上传文件") MultipartFile file) {
        chknowlBooksPresentService.importBookBatch(file);
        return ResponseEntity.ok().build();
    }


    /**
     * 更新书籍图片
     */
    @PostMapping("/book/import/img")
    public ResponseEntity<Void> importBookImgBatch() {
        chknowlBooksPresentService.importBookImgBatch();
        return ResponseEntity.ok().build();
    }

    /**
     * 手动导入课程
     */
    @PostMapping("/video/import")
    public ResponseEntity<Void> importVideoBatch(@NotNull(message = "请上传文件") MultipartFile file) {
        chknowlChVideoService.importVideoBatch(file);
        return ResponseEntity.ok().build();
    }

    /**
     * 导如课程图片
     */
    @PostMapping("/video/import/img")
    public ResponseEntity<Void> importVideoImgBatch(@NotNull(message = "请上传文件") MultipartFile[] files) {
        chknowlChVideoService.importVideoImgBatch(files);
        return ResponseEntity.ok().build();
    }

    /**
     * 手动上传课程视频
     */
    @PostMapping("/video/url")
    public ResponseEntity<Void> addBookUrlBatch(@NotNull(message = "请上传文件") MultipartFile file) {
        chknowlChVideoService.addBookUrlBatch(file);
        return ResponseEntity.ok().build();
    }

    /**
     * 手动导入中药材
     */
    @PostMapping("/drug/import")
    public ResponseEntity<Void> importDrugBatch(@NotNull(message = "请上传文件") MultipartFile file) {
        chknowlChDrgusService.importDrugBatch(file);
        return ResponseEntity.ok().build();
    }

    /**
     * 导入中药分类说明
     */
    @PostMapping("/drug/category/import")
    public ResponseEntity<Void> importDrugCategory(@NotNull(message = "请上传文件") MultipartFile file) {
        chknowlChDrgusService.importDrugCategory(file);
        return ResponseEntity.ok().build();
    }

    /**
     * 手动添加照片路径
     */
    @PostMapping("/drug/url")
    public ResponseEntity<Void> addDrugUrl(@NotNull(message = "请上传文件") MultipartFile[] files) {
        chknowlChDrgusService.addDrugUrl(files);
        return ResponseEntity.ok().build();
    }

    /**
     * 手动性味归经
     */
    @PostMapping("/drug/other/import")
    public ResponseEntity<Void> importDrugOther(@NotNull(message = "请上传文件") MultipartFile file) {
        chknowlChDrgusService.importDrugOther(file);
        return ResponseEntity.ok().build();
    }

    /**
     * 导入方剂
     */
    @PostMapping("/curr/import")
    public ResponseEntity<Void> importCurrBatch(@NotNull(message = "请上传文件") MultipartFile file) {
        chknowlCurrService.importCurrBatch(file);
        return ResponseEntity.ok().build();
    }


    /**
     * 导入医案
     */
    @PostMapping("/consilia/import")
    public ResponseEntity<Void> importConsiliaBatch(@NotNull(message = "请上传文件") MultipartFile file) {
        chknowlConsiliaService.importConsiliaBatch(file);
        return ResponseEntity.ok().build();
    }

    /**
     * 添加书院(课程/书籍/中药/方剂/医案)阅读数量记录
     *
     * @param id    id根据类型判断
     * @param type  类型 1课程 2书籍 3中药 4方剂 5医案
     * @param docId 医生id
     */
    @PostMapping("/chknow/read/count/add")
    public ResponseEntity<Void> addChknowlReadCount(@NotNull(message = "id不能为空") Integer id,
                                                    @NotNull(message = "类型不能为空") Integer type,
                                                    @RequestParam(required = false) Integer docId) {
        chknowlReadCountService.addChknowlReadCount(id, type, docId);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询书院(课程/书籍/中药/方剂/医案)阅读数量
     *
     * @param id    id根据类型判断
     * @param type  类型 1课程 2书籍 3中药 4方剂 5医案
     * @param docId 医生id
     */
    @GetMapping("/chknow/read/count/query")
    public ResponseEntity<Integer> getChknowlReadCountTotal(@NotNull(message = "id不能为空") Integer id,
                                                            @NotNull(message = "类型不能为空") Integer type,
                                                            @RequestParam(required = false) Integer docId) {
        Integer res = chknowlReadCountService.getChknowlReadCountTotal(id, type, docId);
        return ResponseEntity.ok(res);
    }


    /**
     * 查询视频分类
     */
    @GetMapping("/chkonwl/video/category/list")
    public ResponseEntity<List<ChnowlChVideoCategory>> queryVideoCategoryList() {
        List<ChnowlChVideoCategory> list = chknowlChVideoService.queryVideoCategoryList();
        return ResponseEntity.ok(list);
    }


    /**
     * 导入视频时长
     */
    @PostMapping("/chknowl/video")
    public ResponseEntity<Void> queryVideoTotalTime(@NotNull(message = "请上传文件") MultipartFile file) {
        chknowlChVideoService.queryVideoTotalTime(file);
        return ResponseEntity.ok().build();
    }
}

